﻿using _066.App;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Xml.Linq;

namespace _066
{
    public partial class Form3 : Form
    {
        //2024.02.08
        //用来存储传递过来的主键值
        private int Code;
        //用来存储该类的对象
        private static Form3 xg = null;
        public Form3()
        {
            InitializeComponent();
        }
        public Form3(int code)
        {
            InitializeComponent();
            this.Code = code;
        }
        //2024.02.08
        //重写窗口的构造函数，显示选中项的数据
        public Form3(SqlData data)
        {
            InitializeComponent();
            #region
            //string text1 = textBox1.Text;
            //int number1 = Int32.Parse(text1);
            //number1 = data.Code;
            //textBox2.Text = data.Name;
            //textBox3.Text = data.Pwd;
            //textBox4.Text = data.Sex;
            //string text5 = textBox5.Text;
            //int number5 = Int32.Parse(text5);
            //number5 = data.Age;
            //string text6 = textBox6.Text;
            //int number6 = Int32.Parse(text6);
            //number6 = data.Phone;
            #endregion
        }
        private void Form3_Load(object sender, EventArgs e)
        {

        }
        //返回对象的方法2024.02.08
        public static Form3 NewXiuGai(int code)
        {
            if(xg==null || xg.IsDisposed)
            {
                xg = new Form3(code);
            }
            return xg;
        }
        private void button1_Click(object sender, EventArgs e)//修改
        {
            //2024.02.08
            //获取数据

            #region
            //SqlData data = new SqlData();
            //string text1 = textBox1.Text;
            //int number1 = Int32.Parse(text1);
            //number1 = data.Code;
            //textBox2.Text = data.Name;
            //textBox3.Text = data.Pwd;
            //textBox4.Text = data.Sex;
            //string text5 = textBox5.Text;
            //int number5 = Int32.Parse(text5);
            //number5 = data.Age;
            //string text6 = textBox6.Text;
            //int number6 = Int32.Parse(text6);
            //number6 = data.Phone;
            ////1.创建连接数据库字符串
            //string constr = "server=.;database=MyDatabaseOne;user=sa;pwd=35683568";
            //SqlConnection connection = new SqlConnection(constr);
            //try
            //{
            //    connection.Open();
            //    SqlCommand cmd = new SqlCommand();
            //    cmd.Connection = connection;
            //    cmd = connection.CreateCommand();
            //    //拼写语句
            //    cmd.CommandText = "update users set code=@code,name=@name,pwd=@pwd,sex=@sex,age=@age,phone=@phone where code=@code";
            //    cmd.Parameters.Add("@code", data.Code);
            //    cmd.Parameters.Add("@name", data.Name);
            //    cmd.Parameters.Add("@pwd", data.Pwd);
            //    cmd.Parameters.Add("@sex", data.Sex);
            //    cmd.Parameters.Add("@age", data.Age);
            //    cmd.Parameters.Add("@phone", data.Phone);
            //    int count = cmd.ExecuteNonQuery();
            //    if (count > 0)
            //    {
            //        MessageBox.Show("修改成功");
            //    }
            //    else
            //    {
            //        MessageBox.Show("修改失败");
            //    }
            //    connection.Close();
            ////2.创建命令项目
            ////3.新增数据
            //string sqlstr = "insert into users values(04,'黄生','016676','男',28,12345)";
            //cmd.CommandText = sqlstr;
            ////4.执行命令
            //int i = cmd.ExecuteNonQuery();
            //Text = i.ToString();
            //if (i > 0)
            //{
            //    MessageBox.Show("执行成功");
            //}
            //else
            //{
            //    MessageBox.Show("执行失败");
            //}

            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine("执行语句有误，请查验");
            //}
            #endregion
        }
    }
}
